public class Demo12 {

   private  static boolean isQuit=false;
    public static void main(String[] args) throws InterruptedException{
        //boolean isQuit=false;
        Thread t=new Thread(() ->{
            while (!isQuit){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t线程执行结束.");
        });
        t.start();

        Thread.sleep(2000);
        //修改isQuit 变量,就能影响到t线程结束了
        System.out.println("main线程尝试终止t线程");
        isQuit=true;

    }
}
